﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace Royaumes_Libres.Database
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks>Patrick Chabot</remarks>
    public class cSQL
    {
        /// <summary>
        /// Retourne une connection à la Db_Site, ouverte et prêt à l'emploi.
        /// </summary>
        /// <returns>SqlCommand</returns>
        /// <remarks>Patrick Chabot</remarks>
        public static SqlCommand GetDbSiteCommand()
        {
            SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();
            csb.DataSource = Properties.Settings.Default.Server;
            csb.UserID = Properties.Settings.Default.User;
            csb.Password = Properties.Settings.Default.Password;
            csb.InitialCatalog = "Db_Site";

            SqlConnection cn = new SqlConnection();
            cn.ConnectionString = csb.ToString();
            
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Clear();

            return cmd;
        }

        /// <summary>
        /// Retourne une connection à la Db_Jeu, ouverte et prêt à l'emploi.
        /// </summary>
        /// <returns>SqlCommand</returns>
        /// <remarks>Patrick Chabot</remarks>
        public static SqlCommand GetDbJeuCommand()
        {
            SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();
            csb.DataSource = Properties.Settings.Default.Server;
            csb.UserID = Properties.Settings.Default.User;
            csb.Password = Properties.Settings.Default.Password;
            csb.InitialCatalog = "Db_Jeu";

            SqlConnection cn = new SqlConnection();
            cn.ConnectionString = csb.ToString();

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Clear();

            return cmd;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameterName">Nom du paramètre.</param>
        /// <param name="value">Valeur du paramètre.</param>
        /// <param name="dbType">Type du paramètre.</param>
        /// <returns>SqlParameter</returns>
        /// <remarks>Patrick Chabot</remarks>
        public static SqlParameter Param(string parameterName, object value, SqlDbType dbType)
        {
            SqlParameter param = new SqlParameter(parameterName, dbType);
            param.Value = value;
            return param;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameterName">Nom du paramètre.</param>
        /// <param name="value">Valeur du paramètre.</param>
        /// <param name="dbType">Type du paramètre.</param>
        /// <param name="size">Size du paramètre.</param>
        /// <returns>SqlParameter</returns>
        /// <remarks>Patrick Chabot</remarks>
        public static SqlParameter Param(string parameterName, object value, SqlDbType dbType, int size)
        {
            SqlParameter param = new SqlParameter(parameterName, dbType, size);
            param.Value = value;

            return param;
        }

        public static SqlParameter OutputParam(string parameterName, SqlDbType dbType)
        {
            SqlParameter param = new SqlParameter(parameterName, dbType);
            param.Direction = ParameterDirection.Output;
            return param;
        }

        public static SqlParameter ReturnParam(string parameterName, SqlDbType dbType)
        {
            SqlParameter param = new SqlParameter(parameterName, dbType);
            param.Direction = ParameterDirection.ReturnValue;
            return param;
        }


    }
}




//con.Open();
//        SqlCommand cmd = new SqlCommand("spuserdetail", con);
//        cmd.CommandType = CommandType.StoredProcedure;
//        cmd.Parameters.AddWithValue("@UserName", UserName);
//        cmd.Parameters.AddWithValue("@Password", Password);
//        cmd.Parameters.AddWithValue("@Email", Email);
//        cmd.Parameters.AddWithValue("@Country", Country);
//        cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
//        cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;
//        cmd.ExecuteScalar();
//        message = (string)cmd.Parameters["@ERROR"].Value;
//        con.Close();